//head
#include <STC15F2K60S2.H>
#include <iic.h>
#include <Led.h>
#include <ds18B20.h>
#include <Seg.h>
#include <init.h>
#include <Key.h>
//变量
unsigned char Key_Slow_Down,Key_Val,Key_Down,Key_Up,Key_Old;
unsigned char Seg_Slow_Down;
unsigned char Seg_Pos;
unsigned char Seg_Buf[8]={10,10,10,10,10,10,10,10};
unsigned char Seg_Point[8]={0,0,0,0,0,0,0,0};
unsigned char ucLed[8]={0,0,0,0,0,0,0,0};

//Key
void Key_Proc()
{
	if(Key_Slow_Down)return;
	Key_Slow_Down=1;
	
	Key_Val=Key_Read();
	Key_Down=Key_Val&(Key_Val^Key_Old);
	Key_Up=~Key_Val&(Key_Val^Key_Old);
	Key_Old=Key_Val;
	
	
}

//Seg
void Seg_Proc()
{
	if(Seg_Slow_Down)return;
	Seg_Slow_Down=1;
	/*信息获取区域*/
	
	/*数据显示区域*/
	
}

//Led 
void Led_Proc()
{
	
}

//T0
void Timer0_Init(void)		//1毫秒@12.000MHz
{
	AUXR |= 0x80;			//定时器时钟1T模式
	TMOD &= 0xF0;			//设置定时器模式
	TL0 = 0x20;				//设置定时初始值
	TH0 = 0xD1;				//设置定时初始值
	TF0 = 0;				//清除TF0标志
	TR0 = 1;				//定时器0开始计时
	ET0=1;
	EA=1;
}

void Timer0_Server()interrupt 1
{
	if(++Key_Slow_Down==10)Key_Slow_Down=0;
	if(++Seg_Slow_Down==200)Seg_Slow_Down=0;
	if(++Seg_Pos==8)Seg_Pos=0;
	Seg_Disp(Seg_Pos,Seg_Buf[Seg_Pos],Seg_Point[Seg_Pos]);
	Led_Disp(Seg_Pos,ucLed[Seg_Pos]);
}

void main()
{
	System_init();
	Timer0_Init();
	
	while(1)
	{
		
		Key_Proc();
		Seg_Proc();
		Led_Proc();
	}
}